//
//  fenLeicollection.m
//  XMLYFM
//
//  Created by dllo on 15/12/29.
//  Copyright © 2015年 zzl. All rights reserved.
//

#import "fenLeicollection.h"
#import "AppTools.h"
#import "fenLeiDetailModel.h"

#import "ZTAlbumDetailViewController.h"

@interface fenLeicollection()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, assign) NSInteger currentPage;
@property(nonatomic,strong)NSMutableArray *allModleArray;


@end

@implementation fenLeicollection
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self creatSubViews];
        self.allModleArray = [NSMutableArray array];
        
    }

    return self;
}

-(void)creatSubViews
{
    self.currentPage = 1;
    self.myTableVeiw = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
    [self.contentView addSubview:self.myTableVeiw];
    self.myTableVeiw.delegate = self;
    self.myTableVeiw.dataSource = self;
    self.myTableVeiw.rowHeight = 85;
    [self.myTableVeiw registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    //自定义cell Xib注册
    [self.myTableVeiw registerNib:[UINib nibWithNibName:@"FenLelDetailCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"FenLelDetailCell"];

    
}


-(void)getDataTitle:(NSString *)title
{
    
//    NSLog(@"sssss categoryId🐶🐶🐶🐶🐶🐶🐶🐶🐶 = %@",self.categoryId);
//    NSLog(@"mmmmmm Title🐶🐶🐶🐶🐶🐶🐶🐶🐶🐶🐶🐶🐶 = %@",title);
    
    
     NSString *http = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=%@&device=iphone&pageId=%ld&pageSize=20&status=0&tagName=%@", self.categoryId, self.currentPage,title];
    
    [AppTools getDataWithURL:http Block:^(id result) {
        //    NSLog(@"http=%@",http);
        NSMutableDictionary *Dic = result;
        NSMutableArray *list = Dic[@"list"];
        for (NSMutableDictionary *dic in list) {
            //        fenLeiDetailModel *fenleiModel = [[fenLeiDetailModel alloc]init];
            //        [fenleiModel setValuesForKeysWithDictionary:dic];
            //        [self.allModleArray addObject:fenleiModel];
            ZTFavorModel *model = [[ZTFavorModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [self.allModleArray addObject:model];
            [self.myTableVeiw reloadData];
        }
        
    } ErrorBlock:^(NSError *error) {
        
        
    }];
    
    
    
}


//TableView协议方法


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     ZTFavorModel *Fenlei = self.allModleArray[indexPath.row];
//
    [self.fenleiDeleget JumpMusic:Fenlei.albumId Title:Fenlei.title Model:Fenlei];
//    ZTFavorModel *model = self.allModleArray[indexPath.row];
//    ZTAlbumDetailViewController *albumVC = [[ZTAlbumDetailViewController alloc]init];
    

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.allModleArray.count;
    

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ZTFavorModel *fenlei = self.allModleArray[indexPath.row];
    
 static NSString *cellID = @"FenLelDetailCell";
    
    self.cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    self.cell.fenLeiModel = fenlei;
    return self.cell;

}



-(void)setTitle:(NSString *)Title
{

    [self.allModleArray removeAllObjects];
    [self getDataTitle:Title];




}


@end
